//
//  TVisitorableViewController.swift
//  weibo
//
//  Created by 王、小胜 on 16/7/24.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class VisitorableViewController: UITableViewController {
    
    //用户登录标记
    private var userLogon = false//UserAccountViewModel.sharedUserAccount.userLogin
    
    
    //定义全局访客视图
    var visitorView: VisitorView?
    
    override func loadView() {
        //根据用户情况，决定显示的根视图
        userLogon ? super.loadView() : setupVistorView()
    }
    
    //设置访客视图
    private func setupVistorView() {
        
        print("来这里")
        //替换根视图
        visitorView = VisitorView()
        
        view = visitorView
        
        //添加按钮的监听方法
        //注册按钮
       visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        //登录按钮
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
        
    }

}

//MARK - 访客视图监听方法

extension VisitorableViewController {
    //注册
    func visitorViewDidRegister() {
        print("注册一下下嘛")
    }
    
    //登录
    func visitorViewDidLogin() {
        print("登录吧，骚年")
        
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
    }
}





